#include "CSetBoolAttributeCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "CSceneObject.h"

#include "Utils\Utils.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CSetBoolAttributeCommand::CSetBoolAttributeCommand (int id, stringc name, bool newValue)
{
	m_id = id;
	m_name = name;
	m_oldValue = editor->getSceneObjectFromID(id)->m_UserData->getAttributeAsBool(name.c_str());
	m_newValue = newValue;
	if (newValue)
		setDescription(stringw(L"set ") + name.c_str());
	else
		setDescription(stringw(L"unset ") + name.c_str());
}

void CSetBoolAttributeCommand::redo ()
{
	CSceneObject* obj =  editor->getSceneObjectFromID(m_id);
	editor->getSceneObjectFromID(m_id)->m_UserData->setAttribute(m_name.c_str(), m_newValue);
	
	if ( m_name ==  stringc("Wireframe") )
	{
		//SetMaterialFlag(obj->m_SceneNode, EMF_WIREFRAME,m_newValue);		
	}
	else if (m_name == stringc("StartPoint"))
	{
		editor->CheckSpawnPoints( obj , true );
	}
}

void CSetBoolAttributeCommand::undo ()
{
	CSceneObject* obj =  editor->getSceneObjectFromID(m_id);
	editor->getSceneObjectFromID(m_id)->m_UserData->setAttribute(m_name.c_str(), m_oldValue);
	
	if ( m_name ==  stringc("Wireframe") )
	{
		//SetMaterialFlag(obj->m_SceneNode, EMF_WIREFRAME,m_oldValue);
	}
	else if (m_name == stringc("StartPoint"))
	{
		editor->CheckSpawnPoints( obj , false );
	}
}
